#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
	int n; cin >> n;
	priority_queue <ll, vector<ll>, greater<ll>>pq;
	while (n--) {
		int op; cin >> op;
		if (op == 1) {
			int x; cin >> x;
			pq.push(x);
		}
		else if (op == 2) {
			cout << pq.top() << '\n';
		}
		else {
			pq.pop();
		}
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
